//
//  LeftViewController.swift
//  SwiftSideslipLikeQQ
//
//  Created by JohnLui on 15/4/11.
//  Copyright (c) 2015年 com.lvwenhan. All rights reserved.
//

import UIKit

// 侧滑菜单 View Controller
class LeftViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    let titlesDictionary = [("资料更新","left_update"), ("我的辅食","left_fav"), ("好评鼓励","left_comment"), ("关于我们","left_about"), ("全局设置","left_setting"), ("退出账号","left_exit")]

    @IBOutlet weak var settingTableView: UITableView!
    @IBOutlet weak var avatarImageView: UIImageView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        settingTableView.delegate = self
        settingTableView.dataSource = self
        settingTableView.tableFooterView = UIView()
        
        self.view.frame = CGRectMake(0, 0, 320 * 0.78, Common.screenHeight)
        avatarImageView.layer.cornerRadius = 50
        avatarImageView.clipsToBounds = true
        avatarImageView.layer.borderWidth = 0.5
        avatarImageView.layer.borderColor = UIColor.whiteColor().CGColor
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // 处理点击事件
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        let viewController = Common.rootViewController
        
        let performSeguIds = ["custInfoIdentifier","custFoodsIdentifier","showOtherPages","showOtherPages","showOtherPages","exitIdentifier"]
        
        viewController.homeViewController.titleOfOtherPages = titlesDictionary[indexPath.row].0
        viewController.homeViewController.performSegueWithIdentifier(performSeguIds[indexPath.row], sender: self)
        Common.contactsVC.view.removeFromSuperview()
        Common.discoverVC.view.removeFromSuperview()
        viewController.mainTabBarController.tabBar.hidden = true
        viewController.mainTabBarController.selectedIndex = 0
        
         viewController.showHome()
        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titlesDictionary.count
    }
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("leftViewCell1", forIndexPath: indexPath)
        
        cell.backgroundColor = UIColor.clearColor()
//        cell.textLabel!.text = titlesDictionary[indexPath.row].0
        if let imageView = cell.viewWithTag(1) as? UIImageView{
        
            imageView.image = UIImage(named: titlesDictionary[indexPath.row].1)
        }
        if let label = cell.viewWithTag(2) as? UILabel{
        
            label.text = titlesDictionary[indexPath.row].0
        }
        
        return cell
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
